import time
from selenium import webdriver


def login():
    # acount_num = input('请输入账号:\n')
    # passwd_str = input('请输入密码:\n')
    driver = webdriver.Chrome(executable_path='C:\chromedriver\chromedriver.exe')
    url = 'http://mail.163.com/'
    driver.get(url)
    driver.maximize_window()
    time.sleep(5)
    acount_num = 'xxx@163.com'
    passwd_str = 'xxx'

    # 163登陆框是使用iframe进行嵌套的，所以需要先切换到该iframe
    driver.switch_to.frame('x-URS-iframe')

    acount = driver.find_element_by_name('email')
    acount.clear()
    acount.send_keys(acount_num)

    passwd = driver.find_element_by_name('password')
    passwd.clear()
    passwd.send_keys(passwd_str)

    time.sleep(3)
    click_button = driver.find_element_by_id('dologin')
    click_button.click()
    time.sleep(3)
    cur_cookies = driver.get_cookies()[0]
    driver.save_screenshot('screenshot.png')
    return cur_cookies

    # driver.switch_to_default_content()#跳出frame，回到主页面
    #
    # print driver.title#获取标题
    # time.sleep(3)
    #
    # driver.find_element_by_xpath("//*[@id='dvNavTop']/ul/li[2]/span[2]").click()#点击写信
    #
    # driver.find_element_by_class_name('nui-editableAddr-ipt').send_keys('ccie48285@vip.qq.com')#添加收件人
    #
    # driver.find_element_by_xpath("//*[@class='nui-ipt-input'and @type = 'text' and @tabindex = '1']").send_keys('friends')#添加主题
    #
    # driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@class,'APP-editor-iframe')]"))#切换到没有id和name的frame中去
    #
    # driver.find_element_by_class_name("nui-scroll").send_keys('test')#添加正文
    # driver.switch_to_default_content()#退出frame
    #
    # driver.find_element_by_xpath("//*[@class='nui-toolbar-item']/div/span[2]").click()#点击发送
    #
    #
    # time.sleep(10)

if __name__ == '__main__':
    login()
